import { api } from "@/lib/request";
import type { ForgotFormData, VerifyForgotFormData } from "@/schemas/forgot";
import type { Response } from "@/types/response";

// 忘记密码API
export const forgotAPI = {
  // 发送忘记密码验证邮件
  forgot: async (data: ForgotFormData): Promise<Response> => {
    const response = await api.post("/cas/forgot", data);
    return response as unknown as Response;
  },
  
  // 验证忘记密码并重置密码
  verify: async (data: VerifyForgotFormData): Promise<Response> => {
    // 对密码进行 base64 编码
    const encodedData = {
      ...data,
      password: btoa(data.password) // 使用 btoa 进行 base64 编码
    };
    const response = await api.post("/cas/forgot/verify", encodedData);
    return response as unknown as Response;
  },
};
